﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class Login : System.Web.UI.Page
{
    private readonly AMV.BLL.User userBll = new AMV.BLL.User();

    protected void Page_Load(object sender, EventArgs e)
    {

    }


    protected void btnLogin_Click(object sender, ImageClickEventArgs e)
    {
        if (!IsValid) return;

        string loginName = txtLoginName.Text.Trim();
        string password = txtPassword.Text.Trim();

        Response.Write(FormsAuthentication.HashPasswordForStoringInConfigFile(password, "md5"));
        Response.Write("<br>");

        AMV.Model.User user = userBll.GetModelByLoginName(loginName);

        if (user == null)
        {
            MessageBox.ShowMessage(this, "用户名不存在");
        }
        else
        {
            if (user.PasswordMD5 == FormsAuthentication.HashPasswordForStoringInConfigFile(password, "md5"))
            {
                Session.Clear();
                Session[Constance.SESSION_USER_CONTEXT] = user;
                Response.Redirect("./");
            }
            else
            {
                MessageBox.ShowMessage(this, "密码不正确");
            }
        }
    }


    protected void btnReset_Click(object sender, ImageClickEventArgs e)
    {
        txtLoginName.Text = txtPassword.Text = "";
    }
}